﻿using System;

using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Handrise.CDCable.Mobile.Business;

namespace Handrise.CDCable.Mobile.UI
{
    public partial class FrmPictureList :FrmBase
    {
        private string parentForm = "";
        private string linkIDs = "";
        private LinkFileService linkFileService = new LinkFileService();
        private Plan plan = null;

        public FrmPictureList()
        {
            InitializeComponent();
            ttlbrhead.Text = "照片管理";
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.空白);
            ilstbcup.Images.Add(ResourceImage.返回01);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.空白);
            ilstbcdown.Images.Add(ResourceImage.返回02);
        }

        private void FrmPictureList_Load(object sender, EventArgs e)
        {
            if (IsReturn)
                LoadCacheData();
            else
                LoadData();

            //加载关联的图片
            List<LinkFile> linkFiles = linkFileService.GetLinkFileByLinkIDAndType(linkIDs, "jpg");

            idlPhoto.ImageMember = "FullFileName";
            idlPhoto.DataSource = linkFiles;
            idlPhoto.DataBind();

            SetButtonState();
        }

        /// <summary>
        /// 加载数据
        /// </summary>
        private void LoadData()
        {
            parentForm = (string)Parameter[0];
            linkIDs = (string)Parameter[1];

            if (Parameter.Count > 2)
                plan = (Plan)Parameter[2];
        }

        /// <summary>
        /// 加载缓存数据
        /// </summary>
        private void LoadCacheData()
        {
            parentForm = (string)Caches[0];
            linkIDs = (string)Caches[1];

            if (Caches.Count > 2)
                plan = (Plan)Caches[2];
        }


        private void bcOpreate_OnButtonClick(object sender, int buttonIndex)
        {
            switch (buttonIndex)
            {
                case 0: //拍摄
                    //LinkFile linkFile = linkFileService.TaskPicture(linkID);
                    //FormManage.GotoNext("FrmCamera", new object[] { "FrmPictureList", linkFile }, new object[] { parentForm, linkID }, false);
                    break;
                case 2: //返回
                    FormManage.GotoNext(parentForm, null, null, true);
                    break;

            }
        }

        private void idlPhoto_OnItemClick(HandRise.MBHOP.Controls.ImageDataListitem item)
        {
            LinkFile linkFile = (LinkFile)item.DataSource;
            FormManage.GotoNext("FrmPictureSee", new object[]{linkFile,plan}, new object[]{parentForm,linkIDs,plan}, false);
        }

        private void btnPrior_Click(object sender, EventArgs e)
        {
            idlPhoto.PreviousPage();
            SetButtonState();
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            idlPhoto.NextPage();
            SetButtonState();
        }

        private void SetButtonState()
        {
            btnNext.Enabled = idlPhoto.PageCount > 0 && idlPhoto.PageIndex < idlPhoto.PageCount;
            btnPrior.Enabled = idlPhoto.PageCount > 0 && idlPhoto.PageIndex > 1;
        }

    }
}